package top.easyblog.core.dao.auto.mapper;

import java.util.List;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.DeleteProvider;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.InsertProvider;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectKey;
import org.apache.ibatis.annotations.SelectProvider;
import org.apache.ibatis.annotations.Update;
import org.apache.ibatis.annotations.UpdateProvider;
import org.apache.ibatis.type.JdbcType;
import org.springframework.stereotype.Repository;
import top.easyblog.core.dao.auto.model.UrlVisitStatistics;
import top.easyblog.core.dao.auto.model.UrlVisitStatisticsExample;

@Mapper
@Repository
public interface UrlVisitStatisticsMapper {
    @SelectProvider(type=UrlVisitStatisticsSqlProvider.class, method="countByExample")
    long countByExample(UrlVisitStatisticsExample example);

    @DeleteProvider(type=UrlVisitStatisticsSqlProvider.class, method="deleteByExample")
    int deleteByExample(UrlVisitStatisticsExample example);

    @Delete({
        "delete from url_visit_statistics",
        "where id = #{id,jdbcType=BIGINT}"
    })
    int deleteByPrimaryKey(Long id);

    @Insert({
        "insert into url_visit_statistics (pv_count, uv_count, ",
        "ip_count, effective_redirection_count, ",
        "ineffective_redirection_count, compression_code, ",
        "tiny_url_digest, source_url_digest, ",
        "statistics_date, create_time, ",
        "update_time)",
        "values (#{pvCount,jdbcType=BIGINT}, #{uvCount,jdbcType=BIGINT}, ",
        "#{ipCount,jdbcType=BIGINT}, #{effectiveRedirectionCount,jdbcType=BIGINT}, ",
        "#{ineffectiveRedirectionCount,jdbcType=BIGINT}, #{compressionCode,jdbcType=VARCHAR}, ",
        "#{tinyUrlDigest,jdbcType=VARCHAR}, #{sourceUrlDigest,jdbcType=VARCHAR}, ",
        "#{statisticsDate,jdbcType=TIMESTAMP}, #{createTime,jdbcType=TIMESTAMP}, ",
        "#{updateTime,jdbcType=TIMESTAMP})"
    })
    @SelectKey(statement="SELECT LAST_INSERT_ID()", keyProperty="id", before=false, resultType=Long.class)
    int insert(UrlVisitStatistics record);

    @InsertProvider(type=UrlVisitStatisticsSqlProvider.class, method="insertSelective")
    @SelectKey(statement="SELECT LAST_INSERT_ID()", keyProperty="id", before=false, resultType=Long.class)
    int insertSelective(UrlVisitStatistics record);

    @SelectProvider(type=UrlVisitStatisticsSqlProvider.class, method="selectByExample")
    @Results({
        @Result(column="id", property="id", jdbcType=JdbcType.BIGINT, id=true),
        @Result(column="pv_count", property="pvCount", jdbcType=JdbcType.BIGINT),
        @Result(column="uv_count", property="uvCount", jdbcType=JdbcType.BIGINT),
        @Result(column="ip_count", property="ipCount", jdbcType=JdbcType.BIGINT),
        @Result(column="effective_redirection_count", property="effectiveRedirectionCount", jdbcType=JdbcType.BIGINT),
        @Result(column="ineffective_redirection_count", property="ineffectiveRedirectionCount", jdbcType=JdbcType.BIGINT),
        @Result(column="compression_code", property="compressionCode", jdbcType=JdbcType.VARCHAR),
        @Result(column="tiny_url_digest", property="tinyUrlDigest", jdbcType=JdbcType.VARCHAR),
        @Result(column="source_url_digest", property="sourceUrlDigest", jdbcType=JdbcType.VARCHAR),
        @Result(column="statistics_date", property="statisticsDate", jdbcType=JdbcType.TIMESTAMP),
        @Result(column="create_time", property="createTime", jdbcType=JdbcType.TIMESTAMP),
        @Result(column="update_time", property="updateTime", jdbcType=JdbcType.TIMESTAMP)
    })
    List<UrlVisitStatistics> selectByExample(UrlVisitStatisticsExample example);

    @Select({
        "select",
        "id, pv_count, uv_count, ip_count, effective_redirection_count, ineffective_redirection_count, ",
        "compression_code, tiny_url_digest, source_url_digest, statistics_date, create_time, ",
        "update_time",
        "from url_visit_statistics",
        "where id = #{id,jdbcType=BIGINT}"
    })
    @Results({
        @Result(column="id", property="id", jdbcType=JdbcType.BIGINT, id=true),
        @Result(column="pv_count", property="pvCount", jdbcType=JdbcType.BIGINT),
        @Result(column="uv_count", property="uvCount", jdbcType=JdbcType.BIGINT),
        @Result(column="ip_count", property="ipCount", jdbcType=JdbcType.BIGINT),
        @Result(column="effective_redirection_count", property="effectiveRedirectionCount", jdbcType=JdbcType.BIGINT),
        @Result(column="ineffective_redirection_count", property="ineffectiveRedirectionCount", jdbcType=JdbcType.BIGINT),
        @Result(column="compression_code", property="compressionCode", jdbcType=JdbcType.VARCHAR),
        @Result(column="tiny_url_digest", property="tinyUrlDigest", jdbcType=JdbcType.VARCHAR),
        @Result(column="source_url_digest", property="sourceUrlDigest", jdbcType=JdbcType.VARCHAR),
        @Result(column="statistics_date", property="statisticsDate", jdbcType=JdbcType.TIMESTAMP),
        @Result(column="create_time", property="createTime", jdbcType=JdbcType.TIMESTAMP),
        @Result(column="update_time", property="updateTime", jdbcType=JdbcType.TIMESTAMP)
    })
    UrlVisitStatistics selectByPrimaryKey(Long id);

    @UpdateProvider(type=UrlVisitStatisticsSqlProvider.class, method="updateByExampleSelective")
    int updateByExampleSelective(@Param("record") UrlVisitStatistics record, @Param("example") UrlVisitStatisticsExample example);

    @UpdateProvider(type=UrlVisitStatisticsSqlProvider.class, method="updateByExample")
    int updateByExample(@Param("record") UrlVisitStatistics record, @Param("example") UrlVisitStatisticsExample example);

    @UpdateProvider(type=UrlVisitStatisticsSqlProvider.class, method="updateByPrimaryKeySelective")
    int updateByPrimaryKeySelective(UrlVisitStatistics record);

    @Update({
        "update url_visit_statistics",
        "set pv_count = #{pvCount,jdbcType=BIGINT},",
          "uv_count = #{uvCount,jdbcType=BIGINT},",
          "ip_count = #{ipCount,jdbcType=BIGINT},",
          "effective_redirection_count = #{effectiveRedirectionCount,jdbcType=BIGINT},",
          "ineffective_redirection_count = #{ineffectiveRedirectionCount,jdbcType=BIGINT},",
          "compression_code = #{compressionCode,jdbcType=VARCHAR},",
          "tiny_url_digest = #{tinyUrlDigest,jdbcType=VARCHAR},",
          "source_url_digest = #{sourceUrlDigest,jdbcType=VARCHAR},",
          "statistics_date = #{statisticsDate,jdbcType=TIMESTAMP},",
          "create_time = #{createTime,jdbcType=TIMESTAMP},",
          "update_time = #{updateTime,jdbcType=TIMESTAMP}",
        "where id = #{id,jdbcType=BIGINT}"
    })
    int updateByPrimaryKey(UrlVisitStatistics record);
}